Blockly.Blocks['Goertek_Start'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("开始 ");
        this.setNextStatement(true, "time"); //time只能连接time
        this.setColour(310);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_Start'] = function(block) {
    // TODO: Assemble Python into code variable.
    var code = 'Start()' + '\n';
    return code;
};

Blockly.Blocks['Goertek_Lock'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("上锁 ")
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);

        this.setColour(160);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_Lock'] = function(block) {
    // TODO: Assemble Python into code variable.
    //var Disarm = block.getFieldValue('plane');
    //var code = 'Disarm(' + Disarm + ')' + '\n';
    var code = 'Disarm(f1)' + '\n';
    return code;
};

Blockly.Blocks['Goertek_UnLock'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("解锁 ")
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]); //向上只能连接action
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]); //向下只能连接action
        this.setColour(160);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_UnLock'] = function(block) {
    // TODO: Assemble Python into code variable.
    // var Arm = block.getFieldValue('plane');
    // var code = 'Arm(' + Arm + ')' + '\n';
    var code = 'Arm(f1)' + '\n';
    return code;
};

Blockly.Blocks['Goertek_TakeOff'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("起飞 ")
            .appendField(new Blockly.FieldNumber(80, 80, 250), "alt")
            .appendField("(cm)");
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_TakeOff'] = function(block) {
    // TODO: Assemble Python into code variable.
    // var getvalue = block.getFieldValue('plane');
    var alt = block.getFieldValue('alt');
    // var code = 'Takeoff(' + getvalue + ',' + alt + ')' + '\n';
    var code = 'Takeoff(f1,' + alt + ')' + '\n';
    return code;
};
Blockly.Blocks['Goertek_TakeOff2'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("起飞 ")
            .appendField(new Blockly.FieldNumber(100, 100, 250), "alt")
            .appendField("(cm)");
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_TakeOff2'] = function(block) {
    // TODO: Assemble Python into code variable.
    // var getvalue = block.getFieldValue('plane');
    var alt = block.getFieldValue('alt');
    // var code = 'Takeoff(' + getvalue + ',' + alt + ')' + '\n';
    var code = 'Takeoff(f1,' + alt + ')' + '\n';
    return code;
};
Blockly.Blocks['Goertek_Land'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("降落 ")
            // .appendField("flight")
            // .appendField(new Blockly.FieldTextInput("f1"), "land");
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_Land'] = function(block) {
    // TODO: Assemble Python into code variable.
    // var getvalue = block.getFieldValue('land');
    //var code = 'Land(' + getvalue + ')' + '\n';
    var code = 'Land(f1)' + '\n';
    return code; //返回的函数
};

//==============================废弃的====================================================
/*
Blockly.Blocks['Goertek_TimeMin'] = {
  init: function() {
      this.appendDummyInput()
          .appendField("时间 ")
          .appendField("min")
          .appendField(new Blockly.FieldTextInput("1"), "fen")
          .appendField("sec")
          .appendField(new Blockly.FieldTextInput("10"), "miao");

      this.setPreviousStatement(true, null); //null可以连接任何
      this.setNextStatement(true, null);
      this.setColour(310);
      this.setTooltip('');
      this.setHelpUrl('http://www.example.com/');
  }
};
Blockly.Python['Goertek_TimeMin'] = function(block) {
  // TODO: Assemble Python into code variable.
  var fen = block.getFieldValue('fen');

  var sec = block.getFieldValue('miao');
  sec = fen * 60 + sec * 1;
  var code = 'Time(' + sec + ')' + '\n';
  return code;
};

Blockly.Blocks['Goertek_AbsDistance'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("绝对位移")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane")
            .appendField("Vx")
            .appendField(new Blockly.FieldTextInput("0"), "x")
            .appendField("Vy")
            .appendField(new Blockly.FieldTextInput("0"), "y")
            .appendField("Vz")
            .appendField(new Blockly.FieldTextInput("0"), "z");
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(160);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_AbsDistance'] = function(block) {
    var text_plane = block.getFieldValue('plane');
    var text_x = block.getFieldValue('x');
    var text_y = block.getFieldValue('y');
    var text_z = block.getFieldValue('z');
    // TODO: Assemble Python into code variable.
    var code = 'Displacement_Abs(' + text_plane + ',' + text_x + ',' + text_y + ',' + text_z + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_DeltaDistance'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("相对位移")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane")
            .appendField("Vx")
            .appendField(new Blockly.FieldTextInput("0"), "x")
            .appendField("Vy")
            .appendField(new Blockly.FieldTextInput("0"), "y")
            .appendField("Vz")
            .appendField(new Blockly.FieldTextInput("0"), "z");
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(160);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_DeltaDistance'] = function(block) {
    var text_plane = block.getFieldValue('plane');
    var text_x = block.getFieldValue('x');
    var text_y = block.getFieldValue('y');
    var text_z = block.getFieldValue('z');
    // TODO: Assemble Python into code variable.
    var code = 'Displacement_Delta(' + text_plane + ',' + text_x + ',' + text_y + ',' + text_z + ')' + '\n';
    return code;
};


Blockly.Blocks['Goertek_AbsRotation'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("绝对角度")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane")
            .appendField("Ax")
            .appendField(new Blockly.FieldTextInput("0"), "x")
            .appendField("Ay")
            .appendField(new Blockly.FieldTextInput("0"), "y")
            .appendField("Az")
            .appendField(new Blockly.FieldTextInput("0"), "z");
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(160);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_AbsRotation'] = function(block) {
    var text_plane = block.getFieldValue('plane');
    var text_x = block.getFieldValue('x');
    var text_y = block.getFieldValue('y');
    var text_z = block.getFieldValue('z');
    // TODO: Assemble Python into code variable.
    var code = 'Rotation_Abs(' + text_plane + ',' + text_x + ',' + text_y + ',' + text_z + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_DeltaRotation'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("相对角度")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane")
            .appendField("Ax")
            .appendField(new Blockly.FieldTextInput("0"), "x")
            .appendField("Ay")
            .appendField(new Blockly.FieldTextInput("0"), "y")
            .appendField("Az")
            .appendField(new Blockly.FieldTextInput("0"), "z");
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(160);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_DeltaRotation'] = function(block) {
    var text_plane = block.getFieldValue('plane');
    var text_x = block.getFieldValue('x');
    var text_y = block.getFieldValue('y');
    var text_z = block.getFieldValue('z');
    // TODO: Assemble Python into code variable.
    var code = 'Rotation_Delta(' + text_plane + ',' + text_x + ',' + text_y + ',' + text_z + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_PowerOn'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("开机 ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "land");
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(160);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_PowerOn'] = function(block) {
    // TODO: Assemble Python into code variable.
    var getvalue = block.getFieldValue('land');
    var code = 'PowerOn(' + getvalue + ')' + '\n';
    return code; //返回的函数
};

Blockly.Blocks['Goertek_PowerOff'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("关机 ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "land");
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(160);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_PowerOff'] = function(block) {
    // TODO: Assemble Python into code variable.
    var getvalue = block.getFieldValue('land');
    var code = 'PowerOff(' + getvalue + ')' + '\n';
    return code; //返回的函数
};


Blockly.Blocks['block_delay2'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("延时")
        .appendField("ms")
        .appendField(new Blockly.FieldTextInput("1000"), "ms");
    this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
    this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
    this.setColour(160);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  }
};
Blockly.Python['block_delay2'] = function(block) {

  var dropdown_time = block.getFieldValue('ms');
  // TODO: Assemble Python into code variable.
  var code = 'Delay('+dropdown_time+')'+'\n';
  return code;
};
*/